﻿using System;
using System.Collections.Generic;
using System.Text;
using DevExpress.ExpressApp.ConditionalAppearance;

namespace Ascent.QiPei.Module.BusinessObjects.Sales
{
    //[Appearance("已审核", AppearanceItemType = "ViewItem", TargetItems = "*", Criteria = "SoStatus='已审核'", Context = "ListView", BackColor = "Red", FontColor = "Maroon", Priority = 2)]
    public partial class SaleOrder
    {
        public override void AfterConstruction()
        {
            base.AfterConstruction();
            DeliveryDate = DateTime.Now;
        }

        protected override void OnChanged(string propertyName, object oldValue, object newValue)
        {
            base.OnChanged(propertyName, oldValue, newValue);
            switch (propertyName)
            {
                case "TaxIncluded":
                case "TaxRate":
                case "Discount":
                    CalculateAmount();
                    break;
                default:
                    break;
            }
        }

        private void CalculateAmount()
        {
            DiscountAmount = TotalAmount * Discount / 100;
            if (TaxIncluded)
            {
                TaxAmount = (TotalAmount - DiscountAmount) * TaxRate / 100;
            }
            else
            {
                TaxAmount = 0f;
            }

            Amount = TotalAmount - DiscountAmount - TaxAmount;
        }
    }
}
